package com.google.code.mochaccino.framework.security;
/**
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.google.common.base.Preconditions;
import com.google.inject.Injector;
import org.apache.shiro.web.filter.mgt.FilterChainResolver;
import org.apache.shiro.web.mgt.WebSecurityManager;
import org.apache.shiro.web.servlet.AbstractShiroFilter;

/**
 * The Security Filter is meant to be registered as part of the ServletContainer Filter list. It should be
 * the first filter executed to ensure the 'subject' presence while processing context.
 */
public final class SecurityFilter extends AbstractShiroFilter {

	/** Constructor that receives an injector as a parameter (A convenience constructor) */
	public SecurityFilter( Injector injector ) {
		this( injector.getInstance( WebSecurityManager.class ), injector.getInstance( FilterChainResolver.class ) );
	}

	/** Constructor for stand-alone operation. */
	public SecurityFilter( WebSecurityManager manager, FilterChainResolver resolver ) {
		setSecurityManager( Preconditions.checkNotNull( manager, "WebSecurityManager has not been found" ) );
		setFilterChainResolver( Preconditions.checkNotNull( resolver, "FilterChainResolver has not been found" ) );
	}
}
